#include<bits/stdc++.h>
using namespace std;
class _clock
{
    private:
        int hour,minute,second;
    public:
        _clock(int _h=0,int _m=0,int _s=0):hour(_h),minute(_m),second(_s){}
        _clock(const _clock& copy)
        {
            hour=copy.hour;
            minute=copy.minute;
            second=copy.second;
        }
        _clock operator++()
        {
            second++;
            if(second==60)
            {
                second=0;
                minute++;
                if(minute==60)
                {
                    minute=0;
                    hour++;
                    if(hour==12)
                    {
                        hour=0;
                    }
                }
            }
            return *this;
        }
        _clock operator--(int)
        {
            _clock tmp(*this);
            second--;
            if(second==-1)
            {
                second=59;
                minute--;
                if(minute==-1)
                {
                    minute=59;
                    hour--;
                    if(hour==-1)
                    {
                        hour=11;
                    }
                }
            }
            return tmp;
        }
        void display()
        {
            cout<<hour<<":"<<minute<<":"<<second<<endl;
        }
};
int main()
{
    int h,m,s;
    cin>>h>>m>>s;
    _clock ans(h,m,s);
    int t;
    cin>>t;
    while(t--)
    {
        int num;
        cin>>num;
        if(num>0)
        {
            for(int i=0;i<num;++i)
            {
                ++ans;
            }
        }
        else
        {
            num=-num;
            for(int i=0;i<num;++i)
            {
                ans--;
            }
        }
        ans.display();
    }
}